
using System;
using System.Reflection;
using System.Collections;
using UniversalStorageServices;
using UniversalStorageServices.PersistenceManager;

		

namespace Example
{
	
	public interface INameable
	{	
		System.String Name { get; set; }
		
	}
	
	public interface IFilm
	{
		string Id { get; set; }
		System.String Author { get; set; }
		System.String Description { get; set; }
		
	}
	
	
		/// <summary>
	/// <para>
	/// A collection that stores <see cref='Film'/> objects.
	/// </para>
	/// </summary>
	/// <seealso cref='FilmCollection'/>
	[Serializable()]
	public class  FilmCollection : IPersistableCollection 
	{	
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='FilmCollection'/>.
		/// </para>
		/// </summary>
		public FilmCollection()
		{
		}
		
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='FilmCollection'/> based on another <see cref='FilmCollection'/>.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A <see cref='FilmCollection'/> from which the contents are copied
		/// </param>
		public FilmCollection( FilmCollection val)
		{
			this.AddRange(val);	
		}
		
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='FilmCollection'/> containing any array of <see cref='Film'/> objects.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A array of <see cref='Film'/> objects with which to intialize the collection
		/// </param>
		public FilmCollection( Film[] val)
		{
			this.AddRange(val);
		}
		
		public FilmCollection (Entity parentEntity, string role, IPersistableCollection data): base(parentEntity, role, data)
		{
		}
		
		/// <summary>
		/// <para>Represents the entry at the specified index of the <see cref='Film'/>.</para>
		/// </summary>
		/// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
		/// <value>
		/// <para> The entry at the specified index of the collection.</para>
		/// </value>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
		public new Film this[int index] 
		{
			get 
			{
				return ((Film)base[index]);
			}
			set 
			{
				base[index] = value;
			}
		}
		
		/// <summary>
		/// <para>Adds a <see cref='Film'/> with the specified value to the 
		/// <see cref='FilmCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Film'/> to add.</param>
		/// <returns>
		/// <para>The index at which the new element was inserted.</para>
		/// </returns>
		/// <seealso cref='FilmCollection.AddRange'/>
		public int Add( Film val)
		{
			return base.Add(val);
		}
		
	
		
		/// <summary>
		/// <para>
		/// Adds the contents of another <see cref='FilmCollection'/> to the end of the collection.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A <see cref='FilmCollection'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		/// <para>None.</para>
		/// </returns>
		/// <seealso cref='FilmCollection.Add'/>
		public void AddRange( FilmCollection val)
		{
			base.AddRange(val);
		}
		public void AddRange( Film[] val)
		{
			base.AddRange(val);
		}
		
		/// <summary>
		/// <para>Gets a value indicating whether the 
		/// <see cref='FilmCollection'/> contains the specified <see cref='Film'/>.</para>
		/// </summary>
		/// <param name='val'>The <see cref='Film'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='Film'/> is contained in the collection; 
		/// otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='FilmCollection.IndexOf'/>
		public bool Contains( Film val)
		{
			return List.Contains(val);
		}
		
		/// <summary>
		/// <para>Copies the <see cref='FilmCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
		/// specified index.</para>
		/// </summary>
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='FilmCollection'/> .</para></param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <returns>
		/// <para>None.</para>
		/// </returns>
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='FilmCollection'/> is greater than the available space between <paramref name='index'/> and the end of <paramref name='array'/>.</para></exception>
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='System.Array'/>
		public void CopyTo( Film[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		/// <summary>
		/// <para>Returns the index of a <see cref='Film'/> in 
		/// the <see cref='FilmCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Film'/> to locate.</param>
		/// <returns>
		/// <para>The index of the <see cref='Film'/> of <paramref name='val'/> in the 
		/// <see cref='FilmCollection'/>, if found; otherwise, -1.</para>
		/// </returns>
		/// <seealso cref='FilmCollection.Contains'/>
		public int IndexOf( Film val)
		{
			return List.IndexOf(val);
		}
		
		/// <summary>
		/// <para>Inserts a <see cref='Film'/> into the <see cref='FilmCollection'/> at the specified index.</para>
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
		/// <param name='val'>The <see cref='Film'/> to insert.</param>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='FilmCollection.Add'/>
		public void Insert(int index,  Film val)
		{
			List.Insert(index, val);
		}
		
		/// <summary>
		/// <para>Returns an enumerator that can iterate through 
		/// the <see cref='FilmCollection'/> .</para>
		/// </summary>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='System.Collections.IEnumerator'/>
		public new  FilmEnumerator GetEnumerator()
		{
			return new  FilmEnumerator(this);
		}
		
		/// <summary>
		/// <para> Removes a specific <see cref='Film'/> from the 
		/// <see cref='FilmCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Film'/> to remove from the <see cref='FilmCollection'/> .</param>
		/// <returns><para>None.</para></returns>
		/// <exception cref='System.ArgumentException'><paramref name='val'/> is not found in the Collection. </exception>
		public void Remove( Film val)
		{
			List.Remove(val);
		}
		
		public class  FilmEnumerator : IEnumerator
		{
			IEnumerator baseEnumerator;
			IEnumerable temp;
			
			public  FilmEnumerator( FilmCollection mappings)
			{
				this.temp = mappings;
				this.baseEnumerator = temp.GetEnumerator();
			}
			
			public  Film Current 
			{
				get 
				{
					return (( Film)(baseEnumerator.Current));
				}
			}
			
			object IEnumerator.Current 
			{
				get 
				{
					return baseEnumerator.Current;
				}
			}
			
			public bool MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			bool IEnumerator.MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			public void Reset()
			{
				baseEnumerator.Reset();
			}
			
			void IEnumerator.Reset()
			{
				baseEnumerator.Reset();
			}
		}
	}

	
	[Serializable]
	public class Film :  IPersistable, IFilm, INameable 
	{		
	
		protected Entity _Entity;
		
		[NonSerialized]
		protected PersistenceManager _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		PersistenceManager IPersistable.PersistenceManager
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Film()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
		void IPersistable.DeleteChildren()
		{	
	
		}
	
		public System.String Author
		{
			get 
			{ 
				if(_Entity.GetValue("Author") == null)
					return (new System.String[1])[0];
				else
					return (System.String)this._Entity["Author"]; 
			}
		
			set 
			{ 
				this._Entity["Author"] = value; 
			}
		}
		
		public System.String Description
		{
			get 
			{ 
				if(_Entity.GetValue("Description") == null)
					return (new System.String[1])[0];
				else
					return (System.String)this._Entity["Description"]; 
			}
		
			set 
			{ 
				this._Entity["Description"] = value; 
			}
		}
		
		public System.String Name
		{
			get 
			{ 
				if(_Entity.GetValue("Name") == null)
					return (new System.String[1])[0];
				else
					return (System.String)this._Entity["Name"]; 
			}
		
			set 
			{ 
				this._Entity["Name"] = value; 
			}
		}
		
		public Film ()
		{
			
			this._Entity = new Entity(PersistenceManager.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Film (Entity e): this()
		{
			this._Entity = e;
		}

		private ParentRelationships _Parents;

		public ParentRelationships Parents
		{
			get
			{
				if (_Parents == null)
					if (_PersistenceManager == null)
						throw new ApplicationException("Can't call Parents untracked objects");
				else
					_Parents = new ParentRelationships(this);

				return _Parents;
			}
		}

		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public interface ICar
	{
		string Id { get; set; }
		System.String Engine { get; set; }
		System.DateTime Year { get; set; }
		
	}
	
	
		/// <summary>
	/// <para>
	/// A collection that stores <see cref='Car'/> objects.
	/// </para>
	/// </summary>
	/// <seealso cref='CarCollection'/>
	[Serializable()]
	public class  CarCollection : IPersistableCollection 
	{	
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='CarCollection'/>.
		/// </para>
		/// </summary>
		public CarCollection()
		{
		}
		
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='CarCollection'/> based on another <see cref='CarCollection'/>.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A <see cref='CarCollection'/> from which the contents are copied
		/// </param>
		public CarCollection( CarCollection val)
		{
			this.AddRange(val);	
		}
		
		/// <summary>
		/// <para>
		/// Initializes a new instance of <see cref='CarCollection'/> containing any array of <see cref='Car'/> objects.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A array of <see cref='Car'/> objects with which to intialize the collection
		/// </param>
		public CarCollection( Car[] val)
		{
			this.AddRange(val);
		}
		
		public CarCollection (Entity parentEntity, string role, IPersistableCollection data): base(parentEntity, role, data)
		{
		}
		
		/// <summary>
		/// <para>Represents the entry at the specified index of the <see cref='Car'/>.</para>
		/// </summary>
		/// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
		/// <value>
		/// <para> The entry at the specified index of the collection.</para>
		/// </value>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
		public new Car this[int index] 
		{
			get 
			{
				return ((Car)base[index]);
			}
			set 
			{
				base[index] = value;
			}
		}
		
		/// <summary>
		/// <para>Adds a <see cref='Car'/> with the specified value to the 
		/// <see cref='CarCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Car'/> to add.</param>
		/// <returns>
		/// <para>The index at which the new element was inserted.</para>
		/// </returns>
		/// <seealso cref='CarCollection.AddRange'/>
		public int Add( Car val)
		{
			return base.Add(val);
		}
		
	
		
		/// <summary>
		/// <para>
		/// Adds the contents of another <see cref='CarCollection'/> to the end of the collection.
		/// </para>
		/// </summary>
		/// <param name='val'>
		/// A <see cref='CarCollection'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		/// <para>None.</para>
		/// </returns>
		/// <seealso cref='CarCollection.Add'/>
		public void AddRange( CarCollection val)
		{
			base.AddRange(val);
		}
		public void AddRange( Car[] val)
		{
			base.AddRange(val);
		}
		
		/// <summary>
		/// <para>Gets a value indicating whether the 
		/// <see cref='CarCollection'/> contains the specified <see cref='Car'/>.</para>
		/// </summary>
		/// <param name='val'>The <see cref='Car'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='Car'/> is contained in the collection; 
		/// otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='CarCollection.IndexOf'/>
		public bool Contains( Car val)
		{
			return List.Contains(val);
		}
		
		/// <summary>
		/// <para>Copies the <see cref='CarCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
		/// specified index.</para>
		/// </summary>
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='CarCollection'/> .</para></param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <returns>
		/// <para>None.</para>
		/// </returns>
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='CarCollection'/> is greater than the available space between <paramref name='index'/> and the end of <paramref name='array'/>.</para></exception>
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='System.Array'/>
		public void CopyTo( Car[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		/// <summary>
		/// <para>Returns the index of a <see cref='Car'/> in 
		/// the <see cref='CarCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Car'/> to locate.</param>
		/// <returns>
		/// <para>The index of the <see cref='Car'/> of <paramref name='val'/> in the 
		/// <see cref='CarCollection'/>, if found; otherwise, -1.</para>
		/// </returns>
		/// <seealso cref='CarCollection.Contains'/>
		public int IndexOf( Car val)
		{
			return List.IndexOf(val);
		}
		
		/// <summary>
		/// <para>Inserts a <see cref='Car'/> into the <see cref='CarCollection'/> at the specified index.</para>
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
		/// <param name='val'>The <see cref='Car'/> to insert.</param>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='CarCollection.Add'/>
		public void Insert(int index,  Car val)
		{
			List.Insert(index, val);
		}
		
		/// <summary>
		/// <para>Returns an enumerator that can iterate through 
		/// the <see cref='CarCollection'/> .</para>
		/// </summary>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='System.Collections.IEnumerator'/>
		public new  CarEnumerator GetEnumerator()
		{
			return new  CarEnumerator(this);
		}
		
		/// <summary>
		/// <para> Removes a specific <see cref='Car'/> from the 
		/// <see cref='CarCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='Car'/> to remove from the <see cref='CarCollection'/> .</param>
		/// <returns><para>None.</para></returns>
		/// <exception cref='System.ArgumentException'><paramref name='val'/> is not found in the Collection. </exception>
		public void Remove( Car val)
		{
			List.Remove(val);
		}
		
		public class  CarEnumerator : IEnumerator
		{
			IEnumerator baseEnumerator;
			IEnumerable temp;
			
			public  CarEnumerator( CarCollection mappings)
			{
				this.temp = mappings;
				this.baseEnumerator = temp.GetEnumerator();
			}
			
			public  Car Current 
			{
				get 
				{
					return (( Car)(baseEnumerator.Current));
				}
			}
			
			object IEnumerator.Current 
			{
				get 
				{
					return baseEnumerator.Current;
				}
			}
			
			public bool MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			bool IEnumerator.MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			public void Reset()
			{
				baseEnumerator.Reset();
			}
			
			void IEnumerator.Reset()
			{
				baseEnumerator.Reset();
			}
		}
	}

	
	[Serializable]
	public class Car :  IPersistable, ICar, INameable 
	{		
	
		protected Entity _Entity;
		
		[NonSerialized]
		protected PersistenceManager _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		PersistenceManager IPersistable.PersistenceManager
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Car()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
		void IPersistable.DeleteChildren()
		{	
	
		}
	
		public System.String Engine
		{
			get 
			{ 
				if(_Entity.GetValue("Engine") == null)
					return (new System.String[1])[0];
				else
					return (System.String)this._Entity["Engine"]; 
			}
		
			set 
			{ 
				this._Entity["Engine"] = value; 
			}
		}
		
		public System.DateTime Year
		{
			get 
			{ 
				if(_Entity.GetValue("Year") == null)
					return (new System.DateTime[1])[0];
				else
					return (System.DateTime)this._Entity["Year"]; 
			}
		
			set 
			{ 
				this._Entity["Year"] = value; 
			}
		}
		
		public System.String Name
		{
			get 
			{ 
				if(_Entity.GetValue("Name") == null)
					return (new System.String[1])[0];
				else
					return (System.String)this._Entity["Name"]; 
			}
		
			set 
			{ 
				this._Entity["Name"] = value; 
			}
		}
		
		public Car ()
		{
			
			this._Entity = new Entity(PersistenceManager.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Car (Entity e): this()
		{
			this._Entity = e;
		}

		private ParentRelationships _Parents;

		public ParentRelationships Parents
		{
			get
			{
				if (_Parents == null)
					if (_PersistenceManager == null)
						throw new ApplicationException("Can't call Parents untracked objects");
				else
					_Parents = new ParentRelationships(this);

				return _Parents;
			}
		}

		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}

}
